package com.example.administrator.hqq.View.adapter;

import android.util.SparseArray;
import android.view.View;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/12/20 10:40
 * @remark:
 */
public class CommonViewHolder {
    public static <T extends View> T get(View view, int id) {
        SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
        //如果根view没有用来缓存View的集合
        if (viewHolder == null) {
            viewHolder = new SparseArray<View>();
            view.setTag(viewHolder);
            //创建集合和根View关联
        }
        View chidlView = viewHolder.get(id);
        //获取根View储存在集合中的孩纸
        if (chidlView == null) {
            //如果没有改孩纸
            // 找到该孩纸
            chidlView = view.findViewById(id);
            viewHolder.put(id, chidlView);
            //保存到集合
        }
        return (T) chidlView;
    }
}
